import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import { clueSourceVO, clueSourceForm, clueSourceQuery } from '@/api/goods/clueSource/types';

/**
 * 查询线索列表
 * @param query
 * @returns {*}
 */

export const listClueSource = (query?: clueSourceQuery): AxiosPromise<clueSourceVO[]> => {
  return request({
    url: '/order/clueSource/list',
    method: 'get',
    params: query
  });
};

/**
 * 查询线索详细
 * @param id
 */
export const getClueSource = (id: string | number): AxiosPromise<clueSourceVO> => {
  return request({
    url: '/order/clueSource/' + id,
    method: 'get'
  });
};

/**
 * 查询线索详细
 */
export const getClueSourceAllList = (): AxiosPromise<clueSourceVO> => {
  return request({
    url: '/order/clueSource/allList',
    method: 'get'
  });
};

/**
 * 查询线索编号
 */
export const getClueSourceCode = (): AxiosPromise<clueSourceVO> => {
  return request({
    url: '/order/clueSource/getClueSourceNumber',
    method: 'get'
  });
};

/**
 * 新增线索
 * @param data
 */
export const addClueSource = (data: clueSourceForm) => {
  return request({
    url: '/order/clueSource',
    method: 'post',
    data: data
  });
};

/**
 * 修改线索
 * @param data
 */
export const updateClueSource = (data: clueSourceForm) => {
  return request({
    url: '/order/clueSource',
    method: 'put',
    data: data
  });
};

/**
 * 删除线索
 * @param id
 */
export const delClueSource = (id: string | number | Array<string | number>) => {
  return request({
    url: '/order/clueSource/' + id,
    method: 'delete'
  });
};

/**
 * 状态修改
 * @param clueSourceId 客户端id
 * @param status 状态
 */
export function changeStatus(clueSourceId: string, status: string) {
  const data = {
    clueSourceId,
    status
  };
  return request({
    url: '/order/clueSource/changeStatus',
    method: 'put',
    data: data
  });
}

export default {
  list:listClueSource,
  get:getClueSource,
  add:addClueSource,
  update:updateClueSource,
  del:delClueSource,
  getClueSourceAllList:getClueSourceAllList
}